package com.cqupt.scanning.system.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cqupt.scanning.system.admin.entity.DeviceFoot;
import com.cqupt.scanning.system.admin.service.DeviceFootService;
import com.cqupt.scanning.system.utils.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Data: 2021/7/8 16:51
 * @Author: 宋宝梁
 */
@RestController
@RequestMapping("/admin/organization/dev/foot")
public class DeviceFootController {

    private DeviceFootService deviceFootService;

    @Autowired
    public DeviceFootController(DeviceFootService deviceFootService) {
        this.deviceFootService = deviceFootService;
    }

    /**
     * 通过设备id逻辑删除设备(同时删除绑定账号)
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{devId}")
    @PreAuthorize("hasAuthority('plantarScanning.delete')")
    public R delById(@PathVariable("devId") Integer id) {
        return deviceFootService.delById(id);
    }

    /**
     * 获取所有足底扫描设备（支持设备编码模糊查询）
     * @param query
     * @param current
     * @param size
     * @return
     */
    @GetMapping("/getAll")
    @PreAuthorize("hasAuthority('plantarScanning.getAll')")
    public R getAll(@RequestParam("query") String query,
                    @RequestParam(value = "pageNum", defaultValue = "1") Integer current,
                    @RequestParam(value = "pageSize", defaultValue = "10") Integer size) {
        Page<DeviceFoot> page = new Page<>(current, size);
        return deviceFootService.getAll(page, query);
    }
}
